#!/usr/bin/env bash

################################################################################
# Runs misc custom checks on repistory.
#
# Usage:
#     check/misc
################################################################################

# Get the working directory to the repo root.
cd "$( dirname "${BASH_SOURCE[0]}" )"
cd "$(git rev-parse --show-toplevel)"

# Check for non-contrib references to contrib.
results=$(grep -Rl "\bcirq\.contrib\b" cirq | grep -v "cirq/contrib" | grep -v "__")
RESULT=$?
if [ $RESULT -eq 0 ]; then
  echo -e "\033[31m'cirq.contrib' mentioned in non-contrib files:\033[0m"
  echo "${results}"
  echo
  echo -e "\033[31mSource files outside cirq.contrib must not reference cirq.contrib, as this can cause errors for users who 'pip install cirq' instead of 'pip install cirq[contrib]'.\033[0m"
  exit 1
fi

echo -e "\033[32mNo issues\033[0m."
